<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Photos_management extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_photos_model','admin_listing_model','admin_counter_model'));
		$this->load->library('pagination');
		//$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}
	function index()
	{


		//-- Default Value --//
		$status=51;
		$featured=false;
		$search = "";

		if($this->input->post('order')){
			$order = $this->input->post('order');

			switch ($order) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
			}
		}


		$offset = 0 + $this->uri->segment(5);
		
		$total = $this->admin_counter_model->count_all_photos('photos');

		//print "$total";
		//die();

		$perpage = 5;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';
		
		$config['base_url'] = base_url() . 'secure/photos/photos_management/index/';

		
		$cur =base_url()."secure/photos/photos_management/index/";
		$cur = '<a href="'. $cur   .'">&laquo; First</a>';
		$config['full_tag_open'] = '<div class="pagination"><ul>';
		$config['full_tag_close'] = '</ul></div><!--pagination-->';
		$config['first_link'] = '&laquo; First';
		$config['first_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = 'Last &raquo;';
		$config['last_tag_open'] = '<li class="next page" style="display:inline">';
		$config['last_tag_close'] = '</li>';
		$config['next_link'] = 'Next &rarr;';
		$config['next_tag_open'] = '<li class="next page" style="display:inline">';
		$config['next_tag_close'] = '</li>';
		$config['prev_link'] = '&larr; Previous';
		$config['prev_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['prev_tag_close'] = '</li>';
		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';
		$config['num_tag_open'] = '<li class="page">';
		$config['num_tag_close'] = '</li>';
		$config['display_pages'] = FALSE;

		if($status==51)
		{
			//$data['review']['all'] = $this->admin_review_model->get_reviews($featured = $featured, $status = $status, $perpage, $offset);

			$data['admin']['photos'] = $this->admin_photos_model->get_photos($featured = $featured, $status = $status, $perpage,$offset);


			$this->pagination->initialize($config);
		}else{

			$status=1;
			$offset = 0 + $this->uri->segment(5);
			
			$total = $this->admin_counter_model->count_inactive_photos($status);

			$perpage = 10;
			$config['per_page'] = $perpage;
			$config['total_rows'] = $total;
			$config['uri_segment'] = '5';

			$config['base_url'] = base_url() . 'secure/photos/photos_management/inactive/';
			
			$cur =base_url()."secure/photos/photos_management/inactive/";
			$cur = '<a href="'. $cur   .'">&laquo; First</a>';
			$config['full_tag_open'] = '<div class="pagination"><ul>';
			$config['full_tag_close'] = '</ul></div><!--pagination-->';
			$config['first_link'] = '&laquo; First';
			$config['first_tag_open'] = '<li class="prev page" style="display:inline">';
			$config['first_tag_close'] = '</li>';
			$config['last_link'] = 'Last &raquo;';
			$config['last_tag_open'] = '<li class="next page" style="display:inline">';
			$config['last_tag_close'] = '</li>';
			$config['next_link'] = 'Next &rarr;';
			$config['next_tag_open'] = '<li class="next page" style="display:inline">';
			$config['next_tag_close'] = '</li>';
			$config['prev_link'] = '&larr; Previous';
			$config['prev_tag_open'] = '<li class="prev page" style="display:inline">';
			$config['prev_tag_close'] = '</li>';
			$config['cur_tag_open'] = '<li class="active"><a href="">';
			$config['cur_tag_close'] = '</a></li>';
			$config['num_tag_open'] = '<li class="page">';
			$config['num_tag_close'] = '</li>';
			$config['display_pages'] = FALSE;
			
			
			$data['admin']['photos'] = $this->admin_photos_model->get_inactive_photos($featured = $featured, $status = $status, $perpage, $offset);

			$this->pagination->initialize($config);
		}




		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')

		->build('photos/photos',$data);
	}

	function inactive()
	{
		//-- Default Value --//
		$status=1;
		$featured=false;
		$search = "";

		if($this->input->post('order')){
			$order = $this->input->post('order');

			switch ($order) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
			}
		}


		$status=1;
		$offset = 0 + $this->uri->segment(5);
		
		$total = $this->admin_counter_model->count_inactive_photos($status);
			
		$perpage = 10;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';

		$config['base_url'] = base_url() . 'secure/photos/photos_management/inactive/';
		
		$cur =base_url()."secure/photos/photos_management/inactive/";
		$cur = '<a href="'. $cur   .'">&laquo; First</a>';
		$config['full_tag_open'] = '<div class="pagination"><ul>';
		$config['full_tag_close'] = '</ul></div><!--pagination-->';
		$config['first_link'] = '&laquo; First';
		$config['first_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = 'Last &raquo;';
		$config['last_tag_open'] = '<li class="next page" style="display:inline">';
		$config['last_tag_close'] = '</li>';
		$config['next_link'] = 'Next &rarr;';
		$config['next_tag_open'] = '<li class="next page" style="display:inline">';
		$config['next_tag_close'] = '</li>';
		$config['prev_link'] = '&larr; Previous';
		$config['prev_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['prev_tag_close'] = '</li>';
		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';
		$config['num_tag_open'] = '<li class="page">';
		$config['num_tag_close'] = '</li>';
		$config['display_pages'] = FALSE;
		
		$data['admin']['photos'] = $this->admin_photos_model->get_inactive_photos($featured = $featured, $status = $status, $perpage, $offset);

		$this->pagination->initialize($config);

		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')

		->build('photos/photos',$data);
	}

	function change_photos_status($status=NULL,$id=NULL) {
		$this->admin_photos_model->change_status($id, $status);
		redirect('secure/photos/photos_management');
	}
	/*
	 function active_photos($id) {
	$sql = "update photos set status=1 where id=$id";
	$this->db->query($sql);
	redirect('secure/photos/photos_management');
	}
	*/
	/*
	 function delete_photo($id,$image_file){

	$sql="delete from photos where id=$id";
	$this->db->query($sql);
	redirect('secure/photos/photos_management');
	}
	*/
	function delete($id,$image_file) {
		$this->admin_photos_model->delete_photo($id,$image_file);
		redirect('secure/photos/photos_management');
	}
}